SWEP.Base = "weapon_ic_baseweapon"

if SERVER then
	AddCSLuaFile ("shared.lua")
end

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.PrintName			= "BASE GRENADE"
SWEP.Description		= "Unavailable."

SWEP.Slot					= 4
--SWEP.Cost					= 0
SWEP.PurchasePerAmmo		= true
SWEP.IconFont				= "HL2MPTypeDeath"
SWEP.IconLetter				= "4"

SWEP.Primary.ClipSize		= -1
SWEP.Primary.DefaultClip	= 0
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "xbowbolt"

SWEP.Primary.Sound			= Sound ("WeaponFrag.Roll")

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false 
SWEP.Secondary.Ammo			= "none"

SWEP.FiresBullets			= false

SWEP.ViewModel = "models/weapons/v_grenade.mdl"
SWEP.ViewModelFlip = false

SWEP.ViewModelDefPos = Vector (1.0269, -4.7608, 1.8306)
SWEP.ViewModelDefAng = Vector (0, 0, 8.4224)

SWEP.WorldModel = "models/weapons/w_grenade.mdl"
SWEP.HoldType = "grenade"

SWEP.GrenadeType = "inc_grenade_player_base"

if CLIENT then killicon.AddFont("weapon_ic_grenade", SWEP.IconFont, SWEP.IconLetter, Color(255, 80, 0, 255)) end

function SWEP:PrimaryAttack()
	if self.Owner:GetAmmoCount(self.Weapon:GetPrimaryAmmoType()) <= 0 then return end
	self.Weapon:SendWeaponAnim (ACT_VM_PULLBACK_HIGH)
	self.Weapon:SetNextPrimaryFire (CurTime() + 9999)
	self.PullTime = CurTime()
end

function SWEP:Think()
	if self.PullTime and self.PullTime + 0.2 < CurTime() and not self.Owner:KeyDown (IN_ATTACK) then
		self.Weapon:SendWeaponAnim (ACT_VM_THROW)
		self.PullTime = false
		self.ThrowTime = CurTime()
		self.NadeThrown = false
	elseif self.ThrowTime and self.ThrowTime + 0.1 < CurTime() and not self.NadeThrown then
		self:ThrowGrenade ()
		self:TakePrimaryAmmo (1)
		self.NadeThrown = true
	elseif self.ThrowTime and self.ThrowTime + 0.3 < CurTime() then
		self.ThrowTime = false
		if self.Owner:GetAmmoCount(self.Weapon:GetPrimaryAmmoType()) <= 0 then return end
		self.Weapon:SetNextPrimaryFire (CurTime() + 0.5)
		self.Weapon:SendWeaponAnim (ACT_VM_DRAW)
	end
end

function SWEP:ThrowGrenade ()
	if CLIENT then return end
	local nade = ents.Create (self.GrenadeType)
	nade:SetPos (self.Owner:GetShootPos())
	nade:SetOwner (self.Owner)
	nade:Spawn ()
	local phys = nade:GetPhysicsObject()
	if !phys then return end
	phys:SetVelocity (self.Owner:GetAimVector() * 2500)
	phys:AddAngleVelocity (Vector (math.random() - 0.5, math.random() - 0.5, math.random() - 0.5) * 1000)
end

function SWEP:Holster()
	self.PullTime = false
	self.ThrowTime = false
	self.NadeThrown = false
	return true
end

function SWEP:Deploy()
	
end

function SWEP:Reload()
	
end
